package org.ecpkn.PAGridSim.core.gridsimEntity.policy.paPolicy.priority.RM;

import gridsim.ResGridlet;

import java.util.Comparator;

import org.ecpkn.PAGridSim.core.tasksCreation.Job;

public class ComparatorPeriod implements Comparator<ResGridlet> {

	public int compare(ResGridlet rgl0, ResGridlet rgl1) {

		Job job0 = (Job) rgl0.getGridlet();
		Job job1 = (Job) rgl1.getGridlet();
		// TODO:execution time reasonable?
		// period first,then execution time
		int flagPeriod = 0;
		double period0 = job0.getPeriode_();
		double period1 = job1.getPeriode_();
		flagPeriod = (int) (period0 - period1);
		if (flagPeriod == 0) {
			int flagLength = 0;
			double length0 = job0.getGridletLength();
			double length1 = job1.getGridletLength();
			flagLength = (int) (length0 - length1);
			return flagLength;
		} else {
			return flagPeriod;
		}
	}

}
